|
RAIS
3.2
|
00001 00028 using System; 00029 using System.Data; 00030 using System.Configuration; 00031 using System.Collections; 00032 using System.Collections.Generic; 00033 using System.IO; 00034 using System.Web; 00035 using System.Web.Security; 00036 using System.Web.UI; 00037 using System.Web.UI.WebControls; 00038 using System.Web.UI.WebControls.WebParts; 00039 using System.Web.UI.HtmlControls; 00040 using System.Xml; 00041 using Microsoft.Reporting.WebForms; 00042 00043 using RAIS.Common.DynamicMaskManagement; 00044 using RAIS.Common.TableManagement; 00045 using RAIS.UI.Common; 00046 using RAIS.Common.UserManagement; 00047 00048 namespace RAIS.UI.SpecificMasks.Dynamic_Masks 00049 { 00050 public partial class ReportMask : System.Web.UI.Page 00051 { 00052 //********************************************************************* 00053 #region Fields 00054 00057 DynamicMaskData dynamicMaskData; 00058 #endregion 00059 //********************************************************************* 00060 #region Properties 00061 00064 protected bool IsSpecificReport 00065 { 00066 get 00067 { 00068 if (Session["IsSpecificReport"] != null) 00069 return (bool)Session["IsSpecificReport"]; 00070 else return false; 00071 } 00072 } 00076 protected int MaskID 00077 { 00078 get 00079 { 00080 return (Request[Constants.MASK_ID_PARAMETER_NAME] == null) 00081 ? 0 00082 : int.Parse(Request[Constants.MASK_ID_PARAMETER_NAME]); 00083 } 00084 } 00088 protected UserData CurrentUser 00089 { 00090 get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; } 00091 } 00095 protected Dictionary<int, int> FiltersValues 00096 { 00097 get 00098 { 00099 if (this.Session[UI.Common.Constants.FILTERS_VALUES_TAG] == null) 00100 return null; 00101 else 00102 return (Dictionary<int, int>)this.Session[UI.Common.Constants.FILTERS_VALUES_TAG]; 00103 } 00104 set { this.Session[UI.Common.Constants.FILTERS_VALUES_TAG] = value; } 00105 } 00109 protected DataTable SelectedRowsTable 00110 { 00111 get 00112 { 00113 DataTable queryTable = (DataTable)Session["QueryTable"]; 00114 string queryGrouping = Session["QueryGrouping"].ToString(); 00115 if (queryGrouping.Equals(String.Empty)) 00116 { 00117 DataTable result = queryTable.Clone(); 00118 result.Rows.Clear(); 00119 foreach (GridViewRow row in GVspecificReport.Rows) 00120 { 00121 CheckBox cbx = (CheckBox)row.Cells[0].Controls[1]; 00122 if (cbx.Checked) 00123 { 00124 DataRow dataRow = queryTable.Rows[row.RowIndex]; 00125 DataRow newDataRow = result.NewRow(); 00126 for (int i = 0; i < dataRow.ItemArray.Length; i++) 00127 { 00128 newDataRow[i] = dataRow[i]; 00129 } 00130 result.Rows.Add(newDataRow); 00131 } 00132 } 00133 return result; 00134 } 00135 else 00136 { 00137 string param = Session["QueryParameter"].ToString(); 00138 string whereClause = " WHERE "; 00139 bool exec = false; 00140 foreach (GridViewRow row in GVspecificReport.Rows) 00141 { 00142 CheckBox cbx = (CheckBox)row.Cells[0].Controls[1]; 00143 if (cbx.Checked) 00144 { 00145 DataRow dataRow = queryTable.Rows[row.RowIndex]; 00146 whereClause += "[" + queryGrouping + "] = '" + dataRow[0].ToString() + "' OR "; 00147 exec = true; 00148 } 00149 } 00150 whereClause = whereClause.Substring(0, whereClause.Length - 4); 00151 if (exec) 00152 { 00153 string query = "SELECT * FROM [" + dynamicMaskData.DynamicMask.QueryName + "]" + param + whereClause; 00154 DataTable result = SpecificReportManagement.GetDataTableFromQuery(query); 00155 return result; 00156 } 00157 else return new DataTable(); 00158 } 00159 } 00160 } 00164 protected Dictionary<string, DataTable> SpecificReportData 00165 { 00166 get 00167 { 00168 if (Session["SpecificReportData"] != null) 00169 return (Dictionary<string, DataTable>)Session["SpecificReportData"]; 00170 else return null; 00171 } 00172 } 00176 protected string NextSpecificReportName 00177 { 00178 get 00179 { 00180 bool isNext = false; 00181 foreach (KeyValuePair<string, DataTable> pair in SpecificReportData) 00182 { 00183 if (isNext) 00184 return pair.Key; 00185 if (pair.Key.Equals(CurrentSpecificReportName)) 00186 isNext = true; 00187 } 00188 return null; 00189 } 00190 } 00194 protected string PrevSpecificReportName 00195 { 00196 get 00197 { 00198 string prevReportName = null; 00199 foreach (KeyValuePair<string, DataTable> pair in SpecificReportData) 00200 { 00201 if (pair.Key.Equals(CurrentSpecificReportName)) 00202 return prevReportName; 00203 prevReportName = pair.Key; 00204 } 00205 return null; 00206 } 00207 } 00211 protected string CurrentSpecificReportName 00212 { 00213 get 00214 { 00215 return this.dynamicMaskData.DynamicMask.Name; 00216 } 00217 } 00221 protected int CurrentPageIndex 00222 { 00223 get 00224 { 00225 int index = 1; 00226 foreach (KeyValuePair<string, DataTable> pair in SpecificReportData) 00227 { 00228 if (pair.Key.Equals(this.CurrentSpecificReportName)) 00229 return index; 00230 index++; 00231 } 00232 return 0; 00233 } 00234 } 00235 protected bool IsSubreport 00236 { 00237 get 00238 { 00239 return (Request["subreport"] == null) 00240 ? false 00241 : Convert.ToBoolean(Request["subreport"]); 00242 } 00243 } 00244 #endregion 00245 //********************************************************************* 00246 #region Event handlers 00247 protected void Page_PreLoad(object sender, EventArgs e) 00248 { 00249 RAIS.UI.Common.PageManagement.TrimTextBoxValues(this); 00250 } 00257 protected void Page_Load(object sender, EventArgs e) 00258 { 00259 //this.Response.Cache.SetNoStore(); 00260 if (this.CurrentUser == null) 00261 UI.Common.AccessManagement.SignOut(this); 00262 this.LBLresult.Text = string.Empty; 00263 00264 this.dynamicMaskData = DynamicMaskManagement.GetDynamicMaskData( 00265 this.MaskID, 0, 0, this.CurrentUser, false); 00266 00267 if (Session[UI.Common.Constants.SELECTED_CATEGORY_TAG] != null) 00268 Session["SELECTED CATEGORY TAG Backup"] = Session[UI.Common.Constants.SELECTED_CATEGORY_TAG]; 00269 else 00270 Session[UI.Common.Constants.SELECTED_CATEGORY_TAG] = Session["SELECTED CATEGORY TAG Backup"]; 00271 00272 if (((string)Session[UI.Common.Constants.SELECTED_CATEGORY_TAG])=="Query") 00273 LBLquery.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT; 00274 if (((string)Session[UI.Common.Constants.SELECTED_CATEGORY_TAG]) == "Statistics") 00275 LBLstats.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT; 00276 00277 Session["IsSpecificReport"] = SpecificReportManagement.IsSpecificReport(this.dynamicMaskData.DynamicMask.ID); 00278 if (!this.IsSpecificReport) 00279 UI.Common.DynamicMaskManagement.AddFilterControls(this.TBLfilters, this.dynamicMaskData, this.DDL_SelectedIndexChanged); 00280 else 00281 UI.Common.DynamicMaskManagement.AddFilterControlsWithoutChildFilter(this.TBLfilters, this.dynamicMaskData, this.DDL_SelectedIndexChanged); 00282 00283 if (!IsPostBack) 00284 { 00285 UI.Common.PageManagement.InitializePage(this, this.TreeView1); 00286 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name; 00287 this.LBLtitle.Text = this.dynamicMaskData.DynamicMask.Name; 00288 this.HRfilters.Visible = (this.dynamicMaskData.FiltersData.Count != 0); 00289 00290 // this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest); 00291 } 00292 UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault, dynamicMaskData.DynamicMask.ID); 00293 UI.Common.Localisation.TranslatePage(this); 00294 00295 #region SPECIFIC REPORT(S) 00296 if (this.IsSpecificReport && !IsPostBack) 00297 { 00298 int specificReportID = SpecificReportManagement.GetSpecificReportID(this.dynamicMaskData.DynamicMask.ID); 00299 this.TableGroupBy.Visible = true; 00300 BTNpreview.Enabled = false; 00301 BTNexport.Enabled = false; 00302 BTNquery.Visible = true; 00303 this.PNLspecificReportGrid.Visible = true; 00304 this.TBLoptions.Visible = false; 00305 00306 // Init group-by list 00307 foreach (string queryField in SpecificReportManagement.GetQueryFieldsByID(specificReportID)) 00308 { 00309 DDLgroupBy.Items.Add(queryField); 00310 } 00311 00312 if (this.IsSubreport && Session["HasSpecificSubreports"] != null && (bool)Session["HasSpecificSubreports"]) 00313 { 00314 if (this.NextSpecificReportName != null) 00315 { 00316 BTNnext.Visible = true; 00317 BTNpreview.Visible = false; 00318 BTNexport.Visible = false; 00319 } 00320 if (this.PrevSpecificReportName != null) 00321 BTNprev.Visible = true; 00322 LBLpageIndex.Text = " Report " + this.CurrentPageIndex + "/" + this.SpecificReportData.Keys.Count; 00323 LBLpageIndex.Visible = true; 00324 00325 if (this.SpecificReportData[this.CurrentSpecificReportName] != null) 00326 { 00327 // Prev button has been pressed 00328 00329 DataTable queryResult = SpecificReportManagement.GetQueryResult(this.dynamicMaskData.DynamicMask.QueryName, this.getQueryParameter(), String.Empty, this.CurrentUser, this.dynamicMaskData.DynamicMask.ID); 00330 Session["QueryTable"] = queryResult; 00331 Session["QueryGrouping"] = String.Empty; 00332 this.GVspecificReport.DataSource = queryResult; 00333 this.GVspecificReport.DataBind(); 00334 00335 DataRowCollection selectedRows = this.SpecificReportData[this.CurrentSpecificReportName].Rows; 00336 00337 // init previously selected rows 00338 foreach (GridViewRow gridRow in GVspecificReport.Rows) 00339 { 00340 foreach (DataRow selectedRow in selectedRows) 00341 { 00342 int numOfCorrFields = 0; 00343 for (int i = 0; i < selectedRow.ItemArray.Length; i++) 00344 { 00345 if (gridRow.Cells[i + 1].Text.Equals(selectedRow[i].ToString())) 00346 numOfCorrFields++; 00347 } 00348 if (numOfCorrFields == selectedRow.ItemArray.Length) 00349 { 00350 ((CheckBox)gridRow.Cells[0].Controls[1]).Checked = true; 00351 break; 00352 } 00353 } 00354 } 00355 BTNnext.Enabled = true; 00356 } 00357 } 00358 else 00359 { 00360 // Init subreport list 00361 List<string> subreports = SpecificReportManagement.GetSubreports(specificReportID); 00362 if (subreports.Count > 0) 00363 { 00364 BTNpreview.Visible = false; 00365 BTNexport.Visible = false; 00366 BTNnext.Visible = true; 00367 Dictionary<string, DataTable> reportData = new Dictionary<string, DataTable>(); 00368 reportData.Add(this.CurrentSpecificReportName, null); 00369 foreach (string subreport in subreports) 00370 { 00371 reportData.Add(subreport, null); 00372 } 00373 Session["SpecificReportData"] = reportData; 00374 Session["HasSpecificSubreports"] = true; 00375 LBLpageIndex.Text = " Report " + this.CurrentPageIndex + "/" + this.SpecificReportData.Keys.Count; 00376 LBLpageIndex.Visible = true; 00377 } 00378 else 00379 Session["HasSpecificSubreports"] = false; 00380 } 00381 } 00382 #endregion 00383 } 00384 00385 protected void ODSreport_ObjectCreated(object sender, ObjectDataSourceEventArgs e) 00386 { 00387 e.ObjectInstance = this.dynamicMaskData; 00388 } 00395 protected void BTNpreview_Click(object sender, EventArgs e) 00396 { 00397 if (!this.IsSpecificReport) 00398 { 00399 string resultMessage = string.Empty; 00400 Session["ReportName"] = dynamicMaskData.DynamicMask.Name.Replace(' ', '_') + '_' + DateTime.Today.ToString("dd-MM-yyyy"); 00401 bool success = UI.Common.DynamicMaskManagement.ValidateFilterControlsValues(this.TBLfilters, this.dynamicMaskData, ref resultMessage); 00402 if (success) 00403 { 00404 UI.Common.DynamicMaskManagement.InitializeFilterObjectsFromFilterControls(this.TBLfilters, this.dynamicMaskData); 00405 this.SaveFiltersValuesToSession(); 00406 this.Response.Redirect(string.Format("~/ReportViewer.aspx?{0}={1}&{2}={3}" 00407 , Constants.MASK_ID_PARAMETER_NAME 00408 , this.MaskID 00409 , Constants.PAGE_ORIENTATION_PARAMETER_NAME 00410 , this.RBLorientation.SelectedValue)); 00411 } 00412 else 00413 { 00414 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00415 resultMessage, 00416 success); 00417 } 00418 } 00419 else if (this.SelectedRowsTable.Rows.Count > 0) 00420 { 00421 if (!this.IsSubreport || this.SpecificReportData == null || this.SpecificReportData.Keys.Count == 0) 00422 { 00423 Session["SpecificReportDefinition"] = SpecificReportManagement.GetSpecificReportDefinition(SpecificReportManagement.GetSpecificReportID(this.dynamicMaskData.DynamicMask.ID)); 00424 Session["SpecificReportDataTable"] = this.SelectedRowsTable; 00425 Session["SpecificReportData"] = null; 00426 Session["HasSpecificSubreports"] = false; 00427 } 00428 else 00429 { 00430 this.SpecificReportData[this.CurrentSpecificReportName] = this.SelectedRowsTable; 00431 Session["SpecificReportData"] = this.SpecificReportData; 00432 Session["HasSpecificSubreports"] = true; 00433 } 00434 this.Response.Redirect("~/SpecificReportViewer.aspx"); 00435 } 00436 else 00437 { 00438 LBLresult.Text = "No data-rows selected!"; 00439 LBLresult.ForeColor = System.Drawing.Color.Red; 00440 } 00441 } 00448 protected void DDL_SelectedIndexChanged(object sender, EventArgs e) 00449 { 00450 string resultMessage = string.Empty; 00451 bool success = UI.Common.DynamicMaskManagement.ValidateFilterControlsValues(this.TBLfilters, this.dynamicMaskData, ref resultMessage); 00452 if (success) 00453 { 00454 UI.Common.DynamicMaskManagement.InitializeFilterObjectsFromFilterControls(this.TBLfilters, this.dynamicMaskData); 00455 UI.Common.DynamicMaskManagement.GetChildFiltersLookupValues(this.dynamicMaskData); 00456 UI.Common.DynamicMaskManagement.InitializeChildFilterControls(this.TBLfilters, this.dynamicMaskData, sender); 00457 } 00458 else 00459 { 00460 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00461 resultMessage, 00462 success); 00463 } 00464 UI.Common.Localisation.TranslatePage(this); 00465 } 00472 protected void BTNviewInGrid_Click(object sender, EventArgs e) 00473 { 00474 this.PNLgridview.Visible = true; 00475 UI.Common.DynamicMaskManagement.InitializeFilterObjectsFromFilterControls(this.TBLfilters, this.dynamicMaskData); 00476 UI.Common.DynamicMaskManagement.GetDataSetForListMask(this.dynamicMaskData); 00477 UI.Common.DynamicMaskManagement.InitializeListItems(this.GVlist, this.dynamicMaskData); 00478 UI.Common.Localisation.TranslatePage(this); 00479 } 00486 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 00487 { 00488 UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1); 00489 } 00495 protected void LBTNlogout_Click(object sender, EventArgs e) 00496 { 00497 UI.Common.AccessManagement.SignOut(this); 00498 } 00499 00500 protected void BTNexport_Click(object sender, EventArgs e) 00501 { 00502 if (!this.IsSpecificReport) 00503 { 00504 UI.Common.DynamicMaskManagement.InitializeFilterObjectsFromFilterControls(this.TBLfilters, this.dynamicMaskData); 00505 UI.Common.DynamicMaskManagement.GetDataSetForListMask(this.dynamicMaskData); 00506 } 00507 Response.Clear(); 00508 Response.ContentType = "text/plain"; 00509 Response.AddHeader("Content-Disposition", "attachment;filename=" + dynamicMaskData.DynamicMask.Name.Replace(' ', '_') + '_' + DateTime.Today.ToString("dd-MM-yyyy") + ".csv"); 00510 WriteCSVToResponse(); 00511 Response.End(); 00512 } 00513 00514 protected void BTNquery_Click(object sender, EventArgs e) 00515 { 00516 UI.Common.DynamicMaskManagement.InitializeFilterObjectsFromFilterControls(this.TBLfilters, this.dynamicMaskData); 00517 string param = getQueryParameter(); 00518 DataTable dt = SpecificReportManagement.GetQueryResult(this.dynamicMaskData.DynamicMask.QueryName, param, this.DDLgroupBy.SelectedItem.Text, this.CurrentUser, this.dynamicMaskData.DynamicMask.ID); 00519 Session["QueryTable"] = dt; 00520 Session["QueryGrouping"] = DDLgroupBy.SelectedItem.Text; 00521 Session["QueryParameter"] = param; 00522 GVspecificReport.DataSource = dt; 00523 GVspecificReport.DataBind(); 00524 00525 if (GVspecificReport.Rows.Count > 0) 00526 { 00527 BTNexport.Enabled = true; 00528 BTNpreview.Enabled = true; 00529 BTNnext.Enabled = true; 00530 } 00531 } 00532 00533 protected void GVlist_RowDataBound(object sender, GridViewRowEventArgs e) 00534 { 00535 if (e.Row.Cells[0].Controls.Count > 0) 00536 { 00537 if (e.Row.Cells.Count <= 1) 00538 e.Row.Cells[0].Controls[1].Visible = false; 00539 else 00540 e.Row.Cells[0].Controls[1].Visible = true; 00541 } 00542 foreach (TableCell cell in e.Row.Cells) 00543 { 00544 cell.Wrap = false; 00545 } 00546 e.Row.Cells[0].Width = 20; 00547 } 00548 00549 protected void BTNnext_Click(object sender, EventArgs e) 00550 { 00551 if (this.SelectedRowsTable.Rows.Count > 0) 00552 { 00553 this.SpecificReportData[this.CurrentSpecificReportName] = this.SelectedRowsTable; 00554 int maskID = SpecificReportManagement.GetMaskIdByReportName(this.NextSpecificReportName); 00555 this.Response.Redirect("~/Dynamic Masks/ReportMask.aspx?id=" + maskID + "&subreport=true"); 00556 } 00557 else 00558 { 00559 LBLresult.Text = "No data-rows selected!"; 00560 LBLresult.ForeColor = System.Drawing.Color.Red; 00561 } 00562 } 00563 00564 protected void BTNprev_Click(object sender, EventArgs e) 00565 { 00566 int maskID = SpecificReportManagement.GetMaskIdByReportName(this.PrevSpecificReportName); 00567 this.Response.Redirect("~/Dynamic Masks/ReportMask.aspx?id=" + maskID + "&subreport=true"); 00568 } 00569 00570 #endregion Event handlers 00571 //********************************************************************* 00572 #region Private methods 00573 private string getQueryParameter() 00574 { 00575 string param = "("; 00576 foreach (KeyValuePair<int, DynamicMaskFilterData> kvp in dynamicMaskData.FiltersData) 00577 { 00578 DynamicMaskFilterData filterData = kvp.Value; 00579 if (filterData.DynamicMaskFilter.UseInQuery) 00580 { 00581 if (filterData.DynamicMaskFilter.Type == DynamicMaskFilter.FilterType.Lookup) 00582 { 00583 if (filterData.DynamicMaskFilter.Name.Equals("User")) 00584 { 00585 param += this.CurrentUser.ID + ", "; 00586 } 00587 else if (filterData.CurrentLookupValue != 0) 00588 param += filterData.CurrentLookupValue + ", "; 00589 else 00590 param += "NULL, "; 00591 } 00592 else if (filterData.DynamicMaskFilter.Type == DynamicMaskFilter.FilterType.DatesRage) 00593 { 00594 param += "'" + filterData.DateFrom.ToString("yyyyMMdd") + "', '" + filterData.DateUntil.ToString("yyyyMMdd") + "', "; 00595 } 00596 } 00597 } 00598 if (param.Length > 1) 00599 param = param.Substring(0, param.Length - 2); 00600 param += ")"; 00601 return param; 00602 } 00603 private void WriteCSVToResponse() 00604 { 00605 System.Text.StringBuilder sb = new System.Text.StringBuilder(); 00606 StringWriter sw = new StringWriter(sb); 00607 00608 List<DataTable> dataTables = new List<DataTable>(); 00609 if (this.IsSpecificReport && this.SpecificReportData == null) 00610 dataTables.Add(this.SelectedRowsTable); 00611 else if (this.IsSpecificReport && this.SpecificReportData != null) 00612 { 00613 this.SpecificReportData[this.CurrentSpecificReportName] = this.SelectedRowsTable; 00614 foreach (DataTable dt in this.SpecificReportData.Values) 00615 dataTables.Add(dt); 00616 } 00617 else 00618 dataTables.Add(this.dynamicMaskData.DataSet.Tables[0]); 00619 00620 foreach (DataTable dt in dataTables) 00621 { 00622 foreach (DataColumn column in dt.Columns) 00623 { 00624 Response.Write(column.ColumnName); 00625 Response.Write(";"); 00626 } 00627 Response.Write("\n"); 00628 Response.Write("\n"); 00629 for (int i = 0; i < dt.Rows.Count; i++) 00630 { 00631 DataRow row = dt.Rows[i]; 00632 for (int j = 0; j < row.ItemArray.Length; j++) 00633 { 00634 Response.Write(row.ItemArray[j].ToString()); 00635 if (j < row.ItemArray.Length - 1) 00636 Response.Write(";"); 00637 } 00638 if (i < dt.Rows.Count - 1) 00639 Response.Write("\n"); 00640 } 00641 Response.Write("\n"); 00642 Response.Write("\n"); 00643 } 00644 } 00645 protected void SaveFiltersValuesToSession() 00646 { 00647 Dictionary<int, string> filterValues = new Dictionary<int, string>(); 00648 foreach (KeyValuePair<int, DynamicMaskFilterData> kvp in this.dynamicMaskData.FiltersData) 00649 { 00650 DynamicMaskFilterData filterData = kvp.Value; 00651 00652 if (filterData.DynamicMaskFilter.Type == DynamicMaskFilter.FilterType.DatesRage) 00653 filterValues.Add( 00654 filterData.DynamicMaskFilter.ID 00655 , filterData.DateFrom.ToString() 00656 + RAIS.Common.Constants.DATE_UNTIL_LABEL_TEXT 00657 + filterData.DateUntil.ToString()); 00658 else 00659 filterValues.Add(filterData.DynamicMaskFilter.ID, filterData.CurrentLookupValue.ToString()); 00660 } 00661 this.Session[UI.Common.Constants.QUERIES_FILTERS_VALUES_TAG] = filterValues; 00662 } 00663 #endregion Private methods 00664 } 00665 }